﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aspose.Words;
using Maticsoft.Common;


namespace LCrs.Web.personeinfo
{
    public partial class PrintWord : System.Web.UI.Page
    {
        LCrs.BLL.PersonInfo pm = new BLL.PersonInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string pid = Request["pid"];
                string type = Request["type"];

                if (type == "zdtzd")
                {
                    LCrs.Model.PersonInfo p = pm.GetModel(int.Parse(pid));

                    string jsdw = Request["jsdw"];
                    string path = System.Web.HttpContext.Current.Server.MapPath("~/template/zdtzd.docx");
                    Document doc = new Document(path);

                    doc.Range.Replace("姓名1", p.pname, false, true);
                    doc.Range.Replace("接收单位1", jsdw, false,true); 
                    doc.Range.Replace("原工作单位1", p.workname, false, true);
                    doc.Range.Replace("[调字号]", System.DateTime.Now.Year.ToString()+" "+ pid, false, true);

                    string saveDocFile = System.Web.HttpContext.Current.Server.MapPath("~/template/zdtzd1.docx");
                    doc.Save(saveDocFile);

                    System.Diagnostics.Process.Start(saveDocFile);
                }
                if (type == "ddh")
                {
                    LCrs.Model.PersonInfo p = pm.GetModel(int.Parse(pid));

                    string fw = Request["fw"];
                    string drdw = Request["drdw"];
                    string yw = Request["yw"];

                    string path = System.Web.HttpContext.Current.Server.MapPath("~/template/ddh.docx");
                    Document doc = new Document(path);

                    doc.Range.Replace("姓名1", p.pname, false, true);
                    doc.Range.Replace("发往1", fw, false, true);
                    doc.Range.Replace("接收单位1", drdw, false, true);
                    doc.Range.Replace("身份证号1", p.ID, false, true);
                    doc.Range.Replace("原因1 ", p.ID, false, true);
                    doc.Range.Replace("调字号", System.DateTime.Now.Year.ToString() + " " + pid, false, true);
                    doc.Range.Replace("日期", System.DateTime.Now.ToString("yyyy年MM月dd日"), false, true);
                    

                    string saveDocFile = System.Web.HttpContext.Current.Server.MapPath("~/template/ddh1.docx");
                    doc.Save(saveDocFile);

                    System.Diagnostics.Process.Start(saveDocFile);
                }

                
            }
        }

       
    }
}